
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JRadioButton;

import xmlParser.XmlParser;

import extensible.Canvas;
import extensible.Factory;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


/**
 * The collection of buttons to apply commands to the active canvas.
 * 
 * @author Jonathan Su and Jeff Forte
 */
@SuppressWarnings("serial")
public class ButtonPanel extends JPanel
{
    // other user interface components
    private Canvas myView;
    private RangeSlider myNumberToCreate;
    private RangeSlider myTrailSize;
    private RangeSlider myDistanceFrom;
    private RangeSlider myProximityTo; 
    public static final Dimension SIZE = new Dimension(75, 20);


    /**
     * Create a button panel to act on the given target.
     * 
     * @param target canvas upon which commands act on 
     * @param input component that provides additional input to commands
     */
    public ButtonPanel(Canvas target)
    {
    	myView = target;
    }
    
    public ButtonPanel (Canvas target, RangeSlider numberToCreate, RangeSlider trailSize, RangeSlider distanceFrom, RangeSlider proximityTo)
    {
        myView = target;
        myNumberToCreate = numberToCreate;
        myTrailSize = trailSize;
        myDistanceFrom = distanceFrom;
        myProximityTo = proximityTo;
    }


    /**
     * Create a button for the given command.
     * 
     * @param factory command to activate when button is pushed 
     */
    public void add (final Factory factory)
    {
        JButton b = new JButton(factory.getName());
        b.addActionListener(new ActionListener()
            {
                public void actionPerformed (ActionEvent e)
                {
                   if (Applet.READ_FROM_FILE){
                	   factory.createMovers(myView,Applet.PARSER);
                   } else 
                	   factory.createMovers(myView, myNumberToCreate.getValue(), myTrailSize.getValue(), myDistanceFrom.getValue(), myProximityTo.getValue() );
                   myView.repaint();
                }
            });
        add(b);
    }
    

    /**
     * Adds created button to current panel
     * @param button
     * 
     */
	public void addButton(JButton button)
	{
		add(button);
	}
	/**
	 * Adds created RadioButton to current panel.
	 * @param button
	 */
	public void addRadioButton(JRadioButton button)
	{
		add(button);
	}
	
}
